
package au.edu.swin.videoshop.bean;

import java.io.Serializable;
import java.util.Comparator;
import java.util.Date;

import au.edu.swin.videoshop.service.MiscUtil;

public class Reservation implements Serializable{
	private Long mReservationId;
	private TitleMedium mMedium;
	private Store mStore;
	private Customer mCustomer;
	private Date mReservationDate;
	private Date mExpiryDate;
	private ReservationStatus mStatus;
	
	public Reservation() {
	}
	
	/**
	 * @return the medium
	 */
	public TitleMedium getMedium() {
		return mMedium;
	}
	
	/**
	 * @param medium the medium to set
	 */
	public void setMedium(TitleMedium medium) {
		mMedium = medium;
	}
	
	/**
	 * @return the store
	 */
	public Store getStore() {
		return mStore;
	}
	
	/**
	 * @param store the store to set
	 */
	public void setStore(Store store) {
		mStore = store;
	}
	
	/**
	 * @return the customer
	 */
	public Customer getCustomer() {
		return mCustomer;
	}
	
	/**
	 * @param customer the customer to set
	 */
	public void setCustomer(Customer customer) {
		mCustomer = customer;
	}

	/**
	 * @return the reservationId
	 */
	public Long getReservationId() {
		return mReservationId;
	}

	/**
	 * @param resevationId the reservationId to set
	 */
	public void setReservationId(Long reservationId) {
		mReservationId = reservationId;
	}

	/**
	 * @return the reservationDate
	 */
	public Date getReservationDate() {
		return mReservationDate;
	}
	
	/**
	 * @param reservationDate the reservationDate to set
	 */
	public void setReservationDate(Date reservationDate) {
		mReservationDate = MiscUtil.normaliseDate(reservationDate);
	}
	
	/**
	 * @return the expiryDate
	 */
	public Date getExpiryDate() {
		return mExpiryDate;
	}
	
	/**
	 * @param expiryDate the expiryDate to set
	 */
	public void setExpiryDate(Date expiryDate) {
		mExpiryDate = MiscUtil.normaliseDate(expiryDate);
	}
	
	/**
	 * @return the status
	 */
	public ReservationStatus getStatus() {
		return mStatus;
	}
	
	/**
	 * @param status the status to set
	 */
	public void setStatus(ReservationStatus status) {
		mStatus = status;
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj instanceof Reservation) {
			return this.mReservationId.equals(((Reservation)obj).mReservationId);
		}
		return false;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return mReservationId.hashCode();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return mReservationId.toString();
	}
	
	public static class TitleNameComparator implements Comparator{

		/* (non-Javadoc)
		 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
		 */
		public int compare(Object o1, Object o2) {
			return ((Reservation)o1).getMedium().getTitle().getTitleName().compareTo(((Reservation)o2).getMedium().getTitle().getTitleName());
		}
	}
	
	public static class MediumTypeComparator implements Comparator{

		/* (non-Javadoc)
		 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
		 */
		public int compare(Object o1, Object o2) {
			return ((Reservation)o1).getMedium().getMediumType().getName().compareTo(((Reservation)o2).getMedium().getMediumType().getName());
		}
	}
	
	public static class StoreNameComparator implements Comparator{

		/* (non-Javadoc)
		 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
		 */
		public int compare(Object o1, Object o2) {
			return ((Reservation)o1).getStore().getStoreName().compareTo(((Reservation)o2).getStore().getStoreName());
		}
	}
	
	public static class ExpiryDateComparator implements Comparator{

		/* (non-Javadoc)
		 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
		 */
		public int compare(Object o1, Object o2) {
			return ((Reservation)o1).getExpiryDate().compareTo(((Reservation)o2).getExpiryDate());
		}
	}
}
